<div class="row">
	<div class="col-md-12">
		<form id="modelEditForm" class="form-horizontal" action="${request.contextPath}/cms/model/update" method="post" onsubmit="return false">
			<input type="hidden" id="id" name="id" value="${cmsModel.id}">
			<div class="box-body">
				<div class="form-group">
					<label id="modelNameLabel" for="modelName" class="col-sm-2 control-label">名称</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="name" id="modelName" value="${cmsModel.name}" placeholder="输入名称...">
					</div>
				</div>
				<div class="form-group">
					<label id="modelPriorityLabel" for="modelPriority" class="col-sm-2  control-label">优先级</label>
					<div class="col-sm-4">
						<input  class="form-control" name="priority" id="modelPriority" value="${cmsModel.priority}"  type="number" placeholder="输入优先级...">
					</div>
					<label id="modelStatusLabel" for="modelStatus" class="col-sm-1  control-label">状态</label>
					<div class="col-sm-4">
						<select class="form-control" id="modelStatus"  name="validStatus" value="${cmsModel.validStatus}"  style="width: 100%;" placeholder="选择状态...">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="modelDescriptionLabel" class="col-sm-2 control-label" >描述</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="description" id="modelDescription" value="${cmsModel.description}"  placeholder="输入描述...">
					</div>
				</div>
				<div class="form-group">
					<label id="modelRemarkLabel" class="col-sm-2 control-label">备注</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="remark" id="modelRemark" value="${cmsModel.remark}" placeholder="输入备注...">
					</div>
				</div>
				<div class="error-message text-center" >
					<span class="error-icon"></span>
					<span id="error-msg" class="error-msg" ></span>
				</div>
             </div>
			<div class="box-footer">
				<div class="pull-right">
               		<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 更新</button>
               		<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 关闭</button>
				</div>
          	</div>
		</form>
	</div>
</div>
<script type="text/javascript">
function ajaxSubmit(form) {
	
	var $form = $(form);
	
	if ($form.length === 1 && $form.validate()) {
        $.ajax({
            type: 'post',
            url: form.action,
            dataType: "json",
            data: $form.serialize()
        }).done(function(result){
            if (result.success) {
                $("#lgModal").modal('hide');
                alertMsg(result.message,"success");
				dataGridReload();
            } else {
                $form.find(".error-msg").show();
                $form.find(".error-msg").html(result.message);
            }
        });
	}
}

$(function() {
    $("#modelStatus").select2({
        data: StatusStore,
        theme: "bootstrap"
    }).val('${cmsModel.validStatus}').trigger("change");
	var $modelEditForm = $("#modelEditForm");
	$modelEditForm.validate({
        rules: {
            name: {
                required: true
            },
            priority: {
                required: true
            },
            validStatus: {
                required: true
            }
        },
        messages: {
            name:{
                required:"名称不能为空！"
            },
            priority:{
                required:"优先级不能为空！"
            },
            validStatus:{
                required:"状态不能为空！"
            }
        },
		submitHandler:ajaxSubmit,
		errorLabelContainer:".error-msg",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$modelEditForm.find(".error-msg").html(errorList[0].message);
			}else{
				$modelEditForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>